Golang : Split string
Problem :
Need to split this string ADAM, EVE, CALEB, SCOTT, GRANTT, JAMES by comma
Solution :
Use the strings.Split function to split the string
package main
import (
"fmt"
"strings"
)
func main() {
str := "ADAM, EVE, CALEB, SCOTT, GRANTT, JAMES"
strarray := strings.Split(str, ",")
fmt.Println(strarray)
}
Output :
[ADAM EVE CALEB SCOTT GRANTT JAMES]
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+22.1k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+23.7k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+22.2k Golang : Repeat a character by multiple of x factor
+9.8k PHP : Get coordinates latitude/longitude from string
+9.5k Golang : Scramble and unscramble text message by randomly replacing words
+7.2k Javascript : How to get JSON data from another website with JQuery or Ajax ?
+15.8k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+8.8k Golang : Executing and evaluating nested loop in html template
+5.7k Python : Print unicode escape characters and string
+7.2k Golang : Gorrila mux.Vars() function example
+23.6k Golang : Get ASCII code from a key press(cross-platform) example
+18.6k Golang : Aligning strings to right, left and center with fill example